from PyQt5.QtWidgets import QMessageBox

from src.admin.DeleteL_UI import Ui_Form
from PyQt5 import QtWidgets


class DeleteL_Win(QtWidgets.QMainWindow,Ui_Form):
    def __init__(self,mydb, parent=None):
        super(DeleteL_Win, self).__init__(parent=parent)
        #ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('')
        #self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
        #self.setWindowIcon(icon)
        self.setupUi(self)
        self.mydb=mydb

    def myOut(self):
        self.hide()

    def getmydb(self,mydb):
        self.mydb=mydb

    def myReturn(self):
        myselect = "select * from 出租信息表 where 玩具编号 =" + self.lineEdit.text()
        mycursor = self.mydb.cursor()
        try:
            mycursor.execute(myselect)
            result = mycursor.fetchall()
        except Exception as a:
            print(a)
            QMessageBox.critical(self, '错误', '玩具号错误')
        else:
            if len(result) == 0:
                QMessageBox.critical(self, '错误', '玩具未被租借')
            else:
                try:
                    mydelete = "delete from 出租信息表 where 玩具编号 = " + self.lineEdit.text()
                    mycursor.execute(mydelete)
                    self.mydb.commit()
                    QMessageBox.information(self, '成功', '归还成功')
                except Exception as a:
                    print(a)
                    QMessageBox.critical(self, '错误', '归还失败')